package com.thread.exe;

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * 授权车辆追踪器
 * @author wangbingwu
 *
 */
public class DelegatingVehicleTracker {
	private final ConcurrentMap<String, Point> locations;
	private final Map<String, Point> unmodifiableMap;
	
	public DelegatingVehicleTracker(Map<String, Point> locations) {
		this.locations = new ConcurrentHashMap<String, Point>();
		this.unmodifiableMap = Collections.unmodifiableMap(locations);
	}
	
	public Map<String, Point> getLocations(String id){
		return unmodifiableMap; 
	}
	
	public Point getLocation(String id) {
		return locations.get(id);
	}
	
	public void setLocations(String id, int x, int y){
		if(locations.replace(id, new Point(x,  y)) == null){
			throw new IllegalArgumentException("invalid vehicle name: " + id);
		}
	}
}
